﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package {
    import Engine.Classes.*;
    import flash.events.*;
    import Engine.Managers.*;
    import Engine.Interfaces.*;
    import flash.display.*;
    import Engine.Init.*;
    import __AS3__.vec.*;
    import flash.system.*;
    import Engine.*;
    import com.lia.utils.*;
    import flash.ui.*;

    public class BaseGame extends Sprite {

        public var parameters:Object;
        protected var gameUpdateFunction:Function = null;

        public function BaseGame(_arg1:Object=null, _arg2:ZEngineOptions=null){
            Security.allowDomain("*.zynga.com");
            if (LoaderInfo(this.root.loaderInfo).parameters){
                this.addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
            };
            var _local3:ContextMenu = new ContextMenu();
            _local3.hideBuiltInItems();
            contextMenu = _local3;
            if (_arg2 == null){
                _arg2 = new ZEngineOptions();
            };
            GlobalEngine.engineOptions = _arg2;
            GlobalEngine.initializationManager = new InitializationManager();
            Constants.TILE_WIDTH = _arg2.tileWidth;
            Constants.TILE_HEIGHT = _arg2.tileHeight;
            Constants.TILE_SCALE = _arg2.tileScale;
        }
        protected function onAddedToStage(_arg1:Event):void{
            this.removeEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
            this.stage.scaleMode = StageScaleMode.NO_SCALE;
            this.stage.align = StageAlign.TOP_LEFT;
            if (this.parameters == null){
                this.parameters = LoaderInfo(this.stage.loaderInfo).parameters;
            };
            this.initEngine();
            this.init();
        }
        private function initEngine():void{
            var _local2:int;
            GlobalEngine.stage = this.stage;
            GlobalEngine.stage.addEventListener(Event.ENTER_FRAME, this.onEngineEnterFrame, false, 10000);
            GlobalEngine.viewport = (new (GlobalEngine.engineOptions.viewportClass)() as Viewport);
            GlobalEngine.parseFlashVars(this.parameters);
            GlobalEngine.zaspManager = (new (GlobalEngine.engineOptions.zaspManagerClass)() as ZaspManager);
            if (GlobalEngine.getFlashVar("zaspDebug") == "true"){
                GlobalEngine.zaspManager.forceActivateDebugTracking(this);
            };
            if (Config.DEBUG_MODE){
                SWFProfiler.init(this.stage, this);
            };
            GlobalEngine.stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.onFullScreenChanged);
            GlobalEngine.stage.addEventListener(MouseEvent.CLICK, this.onStageMouseClick, false, 3);
            GlobalEngine.stage.addEventListener(KeyboardEvent.KEY_DOWN, this.onStageKeyDown, false, 3);
            GlobalEngine.zaspManager.addStageListeners(GlobalEngine.stage);
            ErrorManager.getInstance().addEventListener(ErrorEvent.ERROR, this.onError);
            TransactionManager.initialize();
            var _local1:Vector.<IEngineComponent> = GlobalEngine.engineOptions.engineComponents;
            if (_local1 != null){
                _local2 = 0;
                while (_local2 < _local1.length) {
                    _local1[_local2].initialize();
                    _local2++;
                };
            };
            GlobalEngine.log("Init", ("Base URL: " + Config.SERVICES_GATEWAY_PATH));
            GlobalEngine.log("Init", ("Asset URLs: " + Config.ASSET_PATHS.join(", ")));
        }
        private function onEngineEnterFrame(_arg1:Event):void{
            ProcessManager.instance.onFrame();
            GlobalEngine.updateTimers();
            if (this.gameUpdateFunction != null){
                this.gameUpdateFunction(_arg1);
            };
        }
        protected function init():void{
        }
        protected function onError(_arg1:ErrorEvent):void{
        }
        protected function onFullScreenChanged(_arg1:FullScreenEvent):void{
            if (GlobalEngine.viewport){
                GlobalEngine.viewport.centerViewport();
            };
        }
        public function disableAllInput():void{
            GlobalEngine.stage.mouseChildren = false;
            InputManager.disableInput();
        }
        public function enableAllInput():void{
            GlobalEngine.stage.mouseChildren = true;
            InputManager.enableInput();
        }
        protected function onStageMouseMove(_arg1:MouseEvent):void{
        }
        protected function onStageMouseClick(_arg1:MouseEvent):void{
            GlobalEngine.lastInputTick = GlobalEngine.currentTime;
        }
        protected function onStageKeyDown(_arg1:KeyboardEvent):void{
            GlobalEngine.lastInputTick = GlobalEngine.currentTime;
            var _local2:Class = GlobalEngine.engineOptions.easterEggManager;
            if (_local2 != null){
                _local2.instance.processKeyStroke(_arg1);
            };
        }
        protected function getDetailString():String{
            return ("");
        }

    }
}//package 
